package chequeTeatinos.beans;


import chequeTeatinos.ejb.ClienteFacade;
import chequeTeatinos.entities.Cliente;
import java.io.Serializable;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

@ManagedBean
@RequestScoped
public class SignupValidationBean implements Validator, Serializable{
    @EJB
    private ClienteFacade clienteFacade;

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        System.err.println(value.toString());
        Cliente c = clienteFacade.find(value);
        if (c != null)
            throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,
                    "Email ya en uso", null));
    }
}
